import java.util.*;
public class Test4 {
    //笔试强训 day16  第二题  神奇数
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int a = in.nextInt();
        int b = in.nextInt();
        int count = 0;
        for(int i = a; i <= b; i++) {
            if(isShenQi(i)) {
                count++;
            }
        }
        System.out.println(count);
    }

    private static boolean isShenQi (int num) {
        //暴力枚举
        String[] strings = {"11","13","17","19","23","29","41","43","47","53","59","61","67","73","79","83","89","97"};  //其实只要写一种  就行  比如  13  和 31 写一个就行
        String str = String.valueOf(num);
        for(int i = 0; i < strings.length; i++) {
            String s1 = strings[i].substring(0,1);
            String s2 = strings[i].substring(1);
            int t1 = str.indexOf(s1);
            int t2;
            if(s1.equals(s2)) {
                t2 = str.indexOf(s2,t1+1);
            }else{
                t2 = str.indexOf(s2);
            }
            if(t1 != -1 && t2 != -1) {
                return true;
            }
        }
        return false;
    }
}
